﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using EpiNEXT.Services.Fields;

namespace EpiNEXT.Services.Validation.Actions
{
    //[Serializable()]
    public abstract class ActionBase : IAction
    {
        [XmlArray("TargetNames")]
        [XmlArrayItem("TargetName", typeof(string))]
        public ObservableCollection<string> TargetNames { get; set; }

        public ActionBase()
            : base()
        {

        }

        public virtual List<IField> GetFieldsInAction(DataEntryInstrument form)
        {
            List<IField> fields = new List<IField>();

            foreach (string fieldName in this.TargetNames)
            {
                if (form.Fields.Contains(fieldName))
                {
                    IField field = form.Fields[fieldName];
                    fields.Add(field);
                }
            }

            return fields;
        }

        public virtual void Execute(Record record)
        {

        }
    }
}
